import { BusinessEnum } from '@/enum/ApiEnum'
import { PeaceColumn } from '@/components/type/PeaceColumn'
import { PeaceActionBtn } from '@/components/type/PeaceActionBtn'

export class TableConfig {
  /**
   * 表格接口
   */
  private _api: (input?: object) => Promise<unknown>
  /**
   * 表格字段
   */
  private _columns: Array<PeaceColumn>
  /**
   * 表格列顶部的操作按钮
   */
  private _headerBtnList: ActionBtn[]
  /**
   * 保存窗口宽度
   */
  private _saveDialogWidth: string
  /**
   * 详情窗口宽度
   */
  private _detailDialogWidth: string

  constructor(
    api: (input?: object) => Promise<unknown>,
    columns: Array<PeaceColumn>,
    headerBtnList?: ActionBtn[],
    saveDialogWidth?: string
  ) {
    this._api = api
    this._columns = columns
    this._headerBtnList = headerBtnList || [
      {name: "新增", api: () => Promise.resolve(), type: "primary", business: BusinessEnum.ADD},
      {name: "导入", api: () => Promise.resolve(), type: "primary", business: BusinessEnum.IMPORT},
      {name: "导出", api: () => Promise.resolve(), type: "info", business: BusinessEnum.EXPORT},
      {name: "批量删除", api: () => Promise.resolve(), type: "error", business: BusinessEnum.BATCH_DEL}
    ]
    this._saveDialogWidth = saveDialogWidth || '60%'
  }

  get api(): (input?: object) => Promise<unknown> {
    return this._api
  }

  get columns(): Array<PeaceColumn> {
    return this._columns
  }

  get headerBtnList(): ActionBtn[] {
    return this._headerBtnList
  }

  get saveDialogWidth(): string {
    return this._saveDialogWidth
  }

  get detailDialogWidth(): string {
    return this._detailDialogWidth
  }
  set api(value: (input?: object) => Promise<unknown>) {
    this._api = value
  }

  set columns(value: Array<PeaceColumn>) {
    this._columns = value
  }

  set headerBtnList(value: ActionBtn[]) {
    this._headerBtnList = value
  }

  set saveDialogWidth(value: string) {
    this._saveDialogWidth = value
  }
  set detailDialogWidth(value: string) {
    this._detailDialogWidth = value
  }
}
